<template>
  <PageContainer>
    <view class="container">
      <Header title="福利券" />
      <TResult
        types="success"
        title="福利券创建成功"
        content="已成功创建福利券,快去分享给好友吧!"
        cancel-text="继续创建"
        confirm-text="立即分享"
        @cancel="cancel"
        confirm-open-tyoe="share"
        @confirm=""
      />
      <FixedCode />
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /* createCouponResult 创建优惠券 */
  import PageContainer from '@/components/PageContainer/index.vue';
  import Header from '@/components/Header/index.vue';
  import TResult from '@/components/TResult/index.vue';
  import FixedCode from '@/components/OfficialAccount/fixedCode.vue';
  import { navigateBack, onLoad } from '@/router';
  import { ref, unref } from 'vue';
  import type { MemberCouponListResult } from '@/api/memberCoupon/types';
  import { onShareAppMessage } from '@dcloudio/uni-app';
  import { useAppShare } from '@/hooks/core/useAppShare';

  const { setWxSharePath } = useAppShare();
  const shareInfo = ref<MemberCouponListResult>();
  onLoad((op) => {
    shareInfo.value = op as MemberCouponListResult;
  });

  const cancel = () => {
    navigateBack();
  };

  onShareAppMessage(() => {
    return {
      title: unref(shareInfo)?.name,
      path: setWxSharePath({
        name: 'memberCouponDetails',
        options: {
          id: unref(shareInfo)?.id as number,
          isShare: true,
        },
      }),
      imageUrl: unref(shareInfo)?.couponCover,
    };
  });
</script>

<style lang="scss" scoped></style>
